//
//  WelcomeViewController.swift
//  SwiftWB
//
//  Created by 钟清 on 17/3/30.
//  Copyright © 2017年 Zhong Qing. All rights reserved.
//

import UIKit
import SDWebImage

class WelcomeViewController: UIViewController {
    
    @IBOutlet weak var iconImageView: UIImageView!
    @IBOutlet weak var welcomeLabel: UILabel!
    @IBOutlet weak var iconBottomCons: NSLayoutConstraint!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        iconImageView.layer.cornerRadius = 45
        iconImageView.layer.masksToBounds = true
        
        /* 断言 */
        assert(UserAccount.loadUserAccount() != nil, "必须授权之后才能显示欢迎界面")
        guard let str = UserAccount.loadUserAccount()?.avatar_large else {
            return
        }
        let url = NSURL(string: str)
        iconImageView.sd_setImageWithURL(url)

    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        iconBottomCons.constant = UIScreen.mainScreen().bounds.height - iconBottomCons.constant

        UIView.animateWithDuration(2.0, animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                
                UIView.animateWithDuration(2.0, animations: { () -> Void in
                    self.welcomeLabel.alpha = 1.0
                    }, completion: { (_) -> Void in
                        NSNotificationCenter.defaultCenter().postNotificationName(SwitchRootViewController, object: true)
                })
        }
    }

}
